﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using ZhouYu.NewWorld.BLL.IService;
using ZhouYu.NewWorld.DAL;
using ZhouYu.NewWorld.Model;
using ZhouYu.NewWorld.ViewModel;

namespace ZhouYu.NewWorld.BLL.Service
{
    public class TouristrouteService : BaseRepository<Touristroute>, ITouristrouteService
    {
        #region 查询旅游路线列表
        /// <summary>
        /// 查询旅游路线列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public ResponseResult GetTouristrouteList(int page, int limit, string data)
        {
            ResponseResult responseResult = new ResponseResult();
            using (var db = new SyDbContext())
            {
                var result = from t in db.Touristroute
                             join h in db.Hotel
                             on t.HotelId equals h.HotelId
                             join s in db.Scenicspot
                             on t.ScenicSpotId equals s.Id
                             select new TouristJoint()
                             {
                                 Id = t.Id,
                                 ProductNumber = t.ProductNumber,
                                 OutPlace = t.OutPlace,
                                 OverPlace = t.OverPlace,
                                 IsThemeTour = t.IsThemeTour,
                                 Price = t.Price,
                                 TName = t.TName,
                                 TDate = t.TDate,
                                 Duration = t.Duration,
                                 RouteIntroduce =t.RouteIntroduce,
                                 HotelId=t.HotelId,
                                 ScenicSpotId=t.ScenicSpotId,
                                 OutDate =t.OutDate,
                                 HotelName = h.HotelName,
                                 ScenicName = s.ScenicName
                             };
                //如果不为空则按条件查询
                if (!string.IsNullOrEmpty(data)) { result = result.Where(a => a.TName.Contains(data)); }
                responseResult.code = 0;
                responseResult.count = result.ToList().Count;
                responseResult.msg = string.Empty;
                //Skip()方法用于查到指定条记录条数时跳出 参数：(page-1)*10 也就是‘规律’
                //Take()方法用于查到指定的条数时将其取出 参数：每页想要显示的条数记录limit
                responseResult.data = result.ToList().Skip((page - 1) * limit).Take(limit);
                return responseResult;
            }
        }
        #endregion

    }
}
